package com.idak.jax.ws.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.idak.jax.ws.model.User;
import com.idak.jax.ws.service.AuthentificationService;

@Controller
public class AuthentificationController {
	
	@Autowired
	private AuthentificationService service;
	
	@RequestMapping(value="/login", method=RequestMethod.GET)
	public String initLoginForm(ModelMap model){
		User user = new User();
		model.addAttribute("user", user);
		return "login";
	}
	
	@RequestMapping(value="/login", method=RequestMethod.POST)
	public String logon(User user){
		if(service.authenticate(user)){
			return "success";
		}else{
			return "login";
		}
	}
}
